package com.tjn.date;

import java.util.Calendar;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class Calendar_ {
    public static void main(String[] args) {
        /*
        Calendar是一个抽象类，构造器是private的
        通过getInstance()方法获取实例
         */
        //获取日历对象
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar);
        System.out.println("年:" + calendar.get(Calendar.YEAR));
        //这里加一是因为返回月的时候是从0开始编号
        System.out.println("月:" + (calendar.get(Calendar.MONTH)+1));
        System.out.println("日:" + calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println("时:" + calendar.get(Calendar.HOUR));
        System.out.println("分:" + calendar.get(Calendar.MINUTE));
        System.out.println("秒:" + calendar.get(Calendar.SECOND));
        //没有提供格式对象，所以不能格式化输出，需要自己格式化
        System.out.println("当前时间是:" + calendar.get(Calendar.YEAR) + "年"
                                        + (calendar.get(Calendar.MONTH)+1) + "月"
                                        + calendar.get(Calendar.DAY_OF_MONTH) + "日"
                                        + calendar.get(Calendar.HOUR) + "时"
                                        + calendar.get(Calendar.MINUTE) + "分"
                                        + calendar.get(Calendar.SECOND) + "秒");
        //把Calendar.HOUR改成Calendar.HOUR_OF_DAY就变成24小时的进制
        System.out.println("当前时间是:" + calendar.get(Calendar.YEAR) + "年"
                                        + (calendar.get(Calendar.MONTH)+1) + "月"
                                        + calendar.get(Calendar.DAY_OF_MONTH) + "日"
                                        + calendar.get(Calendar.HOUR_OF_DAY) + "时"
                                        + calendar.get(Calendar.MINUTE) + "分"
                                        + calendar.get(Calendar.SECOND) + "秒");
    }
}
